package com.code.platform.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验工具类
 * Created by frank on 15-1-12.
 */
public class CheckUtils {

    public static boolean isMobile(String mobile) {
        if (StringUtils.isBlank(mobile)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^(1[0-9]{10})$");
        Matcher matcher = pattern.matcher(mobile);
        return matcher.matches();
    }

    public static boolean isTelephone(String telephone) {
        if (StringUtils.isBlank(telephone)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^(((400)-(\\d{4})-(\\d{3}))|((400)-(\\d{3})-(\\d{4})))$|^((\\d{7,8})|((\\d{4}|\\d{3})-(\\d{7,8})))$");
        Matcher matcher = pattern.matcher(telephone);
        return matcher.matches();
    }

    public static boolean isZipcode(String zipcode) {
        if (StringUtils.isBlank(zipcode)) {
            return false;
        }
        Pattern pattern = Pattern.compile("^[1-9]\\d{5}$");
        Matcher matcher = pattern.matcher(zipcode);
        return matcher.matches();
    }

    public static boolean isEmail(String email) {
        if (StringUtils.isBlank(email)) {
            return false;
        }
        Pattern pattern = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    public static void main(String[] arg) {
        System.out.println(CheckUtils.isTelephone("12345678"));
    }
}
